-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[relay-modern]implement getVariables() for ReactRelayRefetchContainer
#1838
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact cla@fb.com if you have any questions. |
can @kassens @yuzhi @lukecwilliams @josephsavona have a look? |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Per discussion on the thread, we would prefer to avoid the overhead of calculating fragment variables unless they are actually used (or at least confirming that always calculating them doesn't have a large impact). Also note that localVariables
is used as a signal for whether a refetch has occurred: if we always set it to something, we'll need a different signal in order to avoid unnecessary calls to setProps
.
} else if (!this._localVariables) { | ||
} else if (true && !this._localVariables) { | ||
// question: why did we only call `setProps` if contains hasn't refetched? | ||
// shell we always keep _resolver updated no matter whehter comtains has refetched or not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. localVariables
is null when the container is using variables assigned from above, and non-null once data has been refetched. The prev/next ID check above ensures that if new props refer to different objects completely that we will update props. If the new props refer to the same record - this case - then by definition we have already updated the resolver to the correct ids & variables (when the refetch occurred).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for explanation. my understanding is that, _resolver
knows about
- dataID 2. query node 3. variables
a change of dataId
has already been catered for in areEqual(prevIDs, nextIDs)
;
query node won't change because they are statically constructed during building;
variables can change as a result of refetch
so what is the scenario -- where a container hasn't called refetch
, but needs to haves its _resolver
updated -- we are addressing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. This case accounts for possible changes to variables in an ancestor container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool. that makes sense. thanks
Hi @josephsavona |
In addition to what Joe mentioned, I recommend avoiding overloading |
@yuzhi you are absolutely right. but isn't the updated variables that we all care about? |
hmm... I think we can do a data check to e.g.
then we don't need the problem I can see is, say, a user clicks the hope it all makes sense... |
I don't follow. |
@bochen2014 Yeah this type of reverse engineering is error-prone. I agree that we should have some way of getting the variables used to render the current data, when necessary. |
ah.. we can check the |
@josephsavona spot on! I had the same question
this will make sure that default value always get returned no matter what
the |
@josephsavona I think the unit test passed because you didn't specify a default value in argument definition |
@bochen2014 Nope, test passes with a default value too. This line ensures that an argument value is preferred over a default/root value. Is there another case that you are thinking of? You might be seeing an unrelated bug. |
right ..... can you look at |
That's intended, fragment-local variables are passed via an object that keys by fragment name. Can you provide a complete example of the behavior you're seeing and how you'd expect it to behave? |
The screenshot doesn't provide enough context to debug. Can you describe the sequence of events and what data you get vs what you expect? Are you using fragment-local variables - |
I expose I also have this as an indicate that refetch has completed here i am getting runtime variables my |
Ah ok. Simply exporting |
I could be wrong. but it seems that my
so it either be a bug, or I'm doing something wrong I'm now fully convenced that exposing |
Yeah this is tricky: in your screenshot this.props are the props received from the refetch container's parent, which isn't affected by the refetch. The refetch container internally updates the props it provides to the component, using the expected variables. |
It's great that you're digging in and experimenting with the core functions! Care to try updating the getFragmentVariables() function with the logic I described? |
yep! I will have a try ;-) thanks @josephsavona . that has been extremely informative and helpful! |
Sure thing, thanks for contributing! |
done. a piece of cake after you explained how it works (or supposed to work) . thanks @josephsavona again! |
Can you add some unit tests? |
yes I was expecting someone to ask ;-) haha |
Epic thread. 😄 |
aa360c8
to
275a087
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refetch
wasn't setup correctly in ReactRelayRefetchContainer-test
because it didn't pass @arguments
to UserFragment
. I created a RefetchQuery
for it.
I addressed the can I ask someone have a review, as we need this as part of our project migration ( |
ReactRelayRefetchContainer
@josephsavona @yuzhi can you guys have a look ? thanks! |
@bochen2014 Let me see what's up with the test failing tomorrow morning |
@bochen2014 it should be fixed now |
thanks @AGS- . the unit tests now all passed.. can I ask someone to review my changes again and point out issues/problems if any? |
this PR is getting really messy. will create a new one instead |
I created this PR to address issue #1828
the main purpose is to expose
_localVariables
so that they can referred to bythis.props.relay.variables
in components.main idea behind is that,
_getFragmentVariables
always return thefragment
variables which only contains default values becausefragment
are static;_localVariables